package com.live.dengdengtv.activity.login;

import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

import com.live.dengdengtv.BaseActivity;
import com.live.dengdengtv.CustomTitleActivity;
import com.live.dengdengtv.R;
import com.live.dengdengtv.bean.AppInfo;
import com.live.dengdengtv.bean.SimpleInfo;
import com.live.dengdengtv.bean.SimpleInfoData;
import com.live.dengdengtv.net.NetTaskList;
import com.live.dengdengtv.utils.Notice;
import com.live.dengdengtv.utils.ViewClickUtils;
import com.zhy.http.okhttp.OkHttpUtils;

import java.util.HashMap;
import java.util.Map;

import okhttp3.Call;

public class ForgetPwordActivity extends CustomTitleActivity {
    private EditText phone_et;
    private EditText verify_et;
    private EditText password_et;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_forgetpword, R.layout.title_custom_red);
        setDefaultTitle("忘记密码");

        phone_et = (EditText) findViewById(R.id.phone_et);
        verify_et = (EditText) findViewById(R.id.verify_et);
        password_et = (EditText) findViewById(R.id.password_et);

    }

    private void jumpNext() {
        Intent intent = new Intent(context, LoginActivity.class);
        startActivity(intent);
        finish();
    }

    public void onVerifyCodeClick(View view) {
        String phone = phone_et.getText().toString().trim();
        if(TextUtils.isEmpty(phone)){
            Notice.alert(context, "手机号不能为空!");
            return;
        }


        Map<String,String> params = new HashMap<>();
        params.put("token",AppInfo.TOKEN);
        params.put("phone_type",AppInfo.PHONE_TYPE);
        params.put("phone_system_version",AppInfo.getPhone_system_version());
        params.put("phone_app_version",AppInfo.getPhone_app_version());
        params.put("client_id",AppInfo.getClient_id());

        params.put("phone",phone);
        params.put("code_type","2");
        requestData(NetTaskList.getVerify, params,1);
    }


    public void onNextClick(View view) {
        if(ViewClickUtils.isFastClick(2000)){
            return;
        }
        String phone = phone_et.getText().toString().trim();
        String password = password_et.getText().toString().trim();
        String verifyCode = verify_et.getText().toString().trim();

        if(TextUtils.isEmpty(phone) || TextUtils.isEmpty(password)){
            Notice.alert(context, "手机号或密码不能为空!");
            return;
        }
        if(TextUtils.isEmpty(verifyCode)){
            Notice.alert(context, "验证码不能为空!");
            return;
        }


        Map<String,String> params = new HashMap<>();
        params.put("token",AppInfo.TOKEN);
        params.put("phone_type",AppInfo.PHONE_TYPE);
        params.put("phone_system_version",AppInfo.getPhone_system_version());
        params.put("phone_app_version",AppInfo.getPhone_app_version());
        params.put("client_id",AppInfo.getClient_id());

        params.put("phone",phone);
        params.put("new_password",password);
        params.put("code",verifyCode);
        requestData(NetTaskList.modify_password, params,2);
    }

    @Override
    public boolean onResponse(SimpleInfoData response, int id) {
        if(id == 1){
            if(response.result == 0){
                Notice.alert(context, "验证吗已发送!");
            }
        }else if(id == 2){

            if(response.result == 0){
                Notice.alertAndFinish(context, "密码修改成功,请返回登陆!");
            }

        }
        return false;
    }

}
